package com.dhsc.service.impl.yyzhgl;

import com.dhsc.domain.ywzx.yyzhgl.YybkqxxckVo;
import com.dhsc.domain.yypt.LayuiTableVo;
import com.dhsc.exception.MyException;
import com.dhsc.local.dao.yyzhgl.IYybkqxxckDao;
import com.dhsc.service.yyzhgl.IYybkqxxckService;
import com.dhsc.util.CommonUtil;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.page.PageMethod;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName YybkqxxckServiceImpl
 * @description: 营业部考勤信息查看
 * @author: gx
 * @create: 2024-07-25 15:59:30
 **/
@Service
@Slf4j
public class YybkqxxckServiceImpl implements IYybkqxxckService {

    @Autowired
    private IYybkqxxckDao yybkqxxckDao;

    @Override
    public LayuiTableVo queryYybkqxxck(YybkqxxckVo yybkqxxckVo) {
        LayuiTableVo obj = new LayuiTableVo();
        try{
            //状态不为空的话，说明是导出excel发出的请求，不需要开启pageHelper
            if (!CommonUtil.isNotEmptyObj(yybkqxxckVo.getState())){
                PageMethod.startPage(yybkqxxckVo.getPage(),yybkqxxckVo.getLimit());
            }
            List<YybkqxxckVo> list = yybkqxxckDao.queryYybkqxxck(yybkqxxckVo);
            PageInfo<YybkqxxckVo> pageInfo = new PageInfo<>(list);
            obj.setData(list);
            obj.setMsg("");
            obj.setCount(pageInfo.getTotal());
            obj.setCode(0);
        }catch (Exception e){
            log.error("查询营业部考勤信息出错",e);
            throw new MyException("查询营业部考勤信息出错",e);
        }
        return obj;
    }
}
